const formatTime  = require("../../../utils/formatTime")

Page({
	data:{
		skip:0
	},
	async onLoad(){
		wx.showLoading({
		  title: '加载中',
		})
		let skip=this.data.skip
		let res=await wx.cloud.callFunction({
			name:'getMyComments',
			data:{
				skip
			}
		})
		skip+=20
		let list=res.result.res
		let temp
		for(let i=0;i<list.length;i++){
			list[i].time=formatTime.formatTime(list[i].time)
		}
		console.log('res',res)
		this.setData({
			list,skip
		})
		wx.hideLoading()
	},
	jumpPage(e){
        console.log('jumpPage',e)
        wx.navigateTo({
          url: '/pages/orther/content?id='+e.currentTarget.dataset.id,
        })
	},
	async del(e){
		console.log(e)
		let res=await wx.showModal({
			title:'你确定要删除吗？',
			confirmColor:'#f00'
		})
		if(res.confirm){
			console.log('确定')
			let {index,_id}=e.currentTarget.dataset
			let list=this.data.list
			res=await wx.cloud.callFunction({
				name:'delShopComment',
				data:{
					_id
				}
			})
			console.log(res)
			let result,icon='success'
			if(res.result){
				result='删除成功'
				list.splice(index,1)
			}else{
				result='删除失败'
				icon='error'
			}
			wx.showToast({
			  title: result,
			  icon:icon
			})
			this.setData({
				list
			})
		}
	}
})